package com.zy.hospitalward_management_system.service.impl;

import com.baomidou.mybatisplus.extension.service.IService;
import com.zy.hospitalward_management_system.pojo.Bed;
import com.zy.hospitalward_management_system.mapper.BedMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zy
 * @since 2021-01-26
 */
@Service
public class BedServiceImpl extends ServiceImpl<BedMapper, Bed> implements IService<Bed> {

    @Resource
    BedMapper bedMapper;

    /**
     * 传入床位号,更新床位状态
     * @param bedId 床位号
     * @param state 状态 0没人 1有人
     * @return 是否更改成功
     */
    public boolean updateBedStateById(int bedId,int state){
        Bed bed = bedMapper.selectById(bedId);
        if(bed==null){
            System.out.println("updateBedStateById:房间不存在!");
            return false;
        }
        bed.setBedState(state);
        if(bedMapper.updateById(bed)==1){
            return true;
        }
        System.out.println("updateBedStateById:更新失败!");
        return false;
    }

}
